package com.train.springboot.springboottrain.web;

import com.train.springboot.springboottrain.model.Student;
import com.train.springboot.springboottrain.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


@RestController
@Slf4j
public class StudentController {
    @Autowired
    private StudentService studentService;
    @RequestMapping(value = "says")
    public Student queryById(Integer id){
        //调用业务层的方法
        Student student = studentService.queryById(id);


        return student;
    }
    @RequestMapping(value = "/update")
    public @ResponseBody
    Object modifyStudent() {
        int count = 0;
        try {
            Student student = new Student();
            student.setId(1);
            student.setName("Jack");
            student.setAge(33);
            count = studentService.updateStudentById(student);
        } catch (Exception e) {
            e.printStackTrace();
            return "fail";
        }
        return count;
    }



        @RequestMapping(value = "/count")
        public String studentCount(){
            log.debug("查询当前总日志消息");
            log.info("查询当前总日志消息");
            log.warn("查询当前总日志消息");
            log.error("查询当前总日志消息");
            Integer studentCount = studentService.queryStudentCount();
            return "学生人数是："+studentCount;
        }
}
